package utils;

import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;

import receiver.UsbReceiver;

/**
 * Created by eyesee on 2017/6/16.
 */

public class UsbReceiverUtils {

    private static UsbReceiver mReceiver;

    public static void registUsbReceiver(Context context){
        mReceiver = new UsbReceiver();
        IntentFilter filter = new IntentFilter();
        filter.addAction(Intent.ACTION_MEDIA_MOUNTED);
        filter.addAction(Intent.ACTION_MEDIA_CHECKING);
        filter.addAction(Intent.ACTION_MEDIA_EJECT);
        filter.addAction(Intent.ACTION_MEDIA_REMOVED);
        filter.addAction(Intent.ACTION_MEDIA_UNMOUNTED);
        filter.addDataScheme("file");
        context.registerReceiver(mReceiver,filter);
    }

    public static void unregistReceiver(Context context){
        if (mReceiver != null){
            context.unregisterReceiver(mReceiver);
        }
    }
}
